#ifndef _EXDFLASH_H
#define _EXDFLASH_H

#if DFLASH_GD25_USE


#define  ExDflash_Page_Size    256
#define  ExDflash_Sector_Size  16*256
#define  ExDflash_Block_Size   256

           
//DFLASH nHOLD   PORTD_PD0
#define ExDflash_PortHold_Low()        EX_DFLASH_HOLD_L()
#define ExDflash_PortHold_High()       EX_DFLASH_HOLD_H()

//DFLASH  nWP    PORTD_PD1
#define ExDflash_PortWP_Low()          EX_DFLASH_WP_L()
#define ExDflash_PortWP_High()         EX_DFLASH_WP_H()

//DFLASH CS      PTH_PTH3
#define ExDflash_CS_Enable()           EX_DFLASH_CS_EN() //Select ExDflash: Chip Select pin low
#define ExDflash_CS_Disable()          EX_DFLASH_CS_DISEN()  //Deselect ExDflash: Chip Select pin high
   


//SPI NOR CMD

#define ExDflash_CMD_NOR_WRITE          0x02  /*!< Write to Memory instruction */
#define ExDflash_CMD_NOR_WRSR           0x01  /*!< Write Status Register instruction */
#define ExDflash_CMD_NOR_WREN           0x06  /*!< Write enable instruction */
#define ExDflash_CMD_NOR_WDIS           0x04   /*!< Write disable instruction */
#define ExDflash_CMD_NOR_READ           0x03  /*!< Read from Memory instruction */
#define ExDflash_CMD_NOR_SFDP           0x5A  /*!< Read from Memory instruction */
#define ExDflash_CMD_NOR_RDSR           0x05  /*!< Read Status Register instruction  */
#define ExDflash_CMD_NOR_MISR           0x35  /*!< Read Status Register instruction Midde Byte */
#define ExDflash_CMD_NOR_HISR           0x15  /*!< Read Status Register instruction Hige Byte */
#define ExDflash_CMD_NOR_RDID           0x9F  /*!< Read identification */
#define ExDflash_CMD_NOR_SE             0x20  /*!< Sector Erase instruction */
#define ExDflash_CMD_NOR_BE             0xD8  /*!< Block Erase instruction */
#define ExDflash_CMD_NOR_CE             0xC7  /*!< Chip Erase instruction */

#define ExDflash_WIP_FLAG           	0x01  /*!< Write In Progress (WIP) flag */


// SPI Nor function
extern void ExDflash_Init(void);
extern void ExDflash_WriteEnable(void);
extern void ExDflash_WriteDisable(void);
extern uint8_t ExDflash_NOR_RD_1Bytle(uint32_t ReadAddr);
void ExDflash_NOR_WR_1Bytle(uint32_t WriteAddr,uint8_t data);
extern uint32_t ExDflash_NOR_ReadID(void);
extern void ExDflash_NOR_WaitForWriteEnd(void);
extern void ExDflash_NOR_ChipErase(void);
extern void ExDflash_NOR_SectorErase(uint32_t SectorAddr);
extern void ExDflash_NOR_BlockErase(uint32_t BlockAddr);
extern void ExDflash_NOR_Read(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead);
extern void ExDflash_NOR_Pageprogram(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
extern void ExDflash_NOR_SFDP_Read(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead);


#endif

#endif // __ExDflash_SPI_H__
